Ext.define('DCApp.view.login.Login', {
    extend: 'Ext.window.Window',
    
    requires: [
        'DCApp.view.login.LoginController',
        'DCApp.view.login.LoginModel',
        'Ext.form.Panel',
        'Ext.button.Button',
        'Ext.form.field.Text',
        'Ext.form.field.ComboBox'
    ],
    
    viewModel: 'login',
    
    controller: 'login',
    bodyPadding: 10,
    title: '登录 - 欢迎使用本系统',
    closable: false,
    
    cls: 'login',
    
    items: {
        xtype: 'form',
        reference: 'form',
        items: [{
            name: 'username',
            //bind: '{username}',
            fieldLabel: '用户名',
    		allowBlank: false,
    	    xtype: 'textfield',
    	    value:'admin'
        }, {
            xtype: 'textfield',
            name: 'password',
            inputType: 'password',
            fieldLabel: '密码',
            allowBlank: false,
            enableKeyEvents: true,
            cls: 'password',
            value:'admin',
            listeners: {
                specialKey: 'onSpecialKey'
            }
        },{
          xtype:'fieldset',
          checkboxName:'changepwd',
          checkboxToggle:true,
          title: '修改我的密码',
          collapsed: true,
          autoHeight:true,
          defaultType: 'textfield',
         // defaults: {width: 300},
          padding:10,
          items :[{
                  fieldLabel: '新密码',
                  name: 'pwd1',              
                  inputType: 'password',
                  msgTarget :'side',
               	validator:function(val){
               		var fm=this.up('form');
              		var btn_ok = fm.up('window').down('button[text=确定]');
              		var fld_pwd2 = fm.down('field[name=pwd2]');
             	  	if(fld_pwd2.isValid()){
             	  	 btn_ok.enable();
  	            	  return true;
             	  	}
	            	else{
	            		btn_ok.disable();
	            		return '密码输入不一致';  
	            	}
	            }	                                
              },{
                  fieldLabel: '确认新密码',
                  inputType: 'password',
                  msgTarget :'side',
                  name: 'pwd2',
             	validator:function(val){
               		var fm=this.up('form');
              		var btn_ok = fm.up('window').down('button[text=确定]');
              		var fld_pwd1 = fm.down('field[name=pwd1]');
             	  	if(val==fld_pwd1.getValue()){
             	  		fld_pwd1.clearInvalid( )
             	  		 btn_ok.enable();
             	  		return true;
             	  	}
	            	else{
	            		btn_ok.disable();
	            		return '密码输入不一致';  
	            	}
	            }	                                
              }
           ]
      }]
    },

    buttons: [{
        text: '确定',
        listeners: {
            click: 'onLoginClick'
        }
    }],
    
    listeners: {
        afterRender: function(thisForm, options){
            this.keyNav = Ext.create('Ext.util.KeyNav', this.el, {                    
                enter: function(){
                	var btn_ok = this.down('button[text=确定]');
                	btn_ok.fireEvent('click',btn_ok); 
                },
                scope: this
            });
        }
    }   
});
